package com.treasure.mall.biz.repository.live;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.live.LiveRoomPO;
import com.treasure.mall.zbq.common.ienum.live.LiveEnums;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * <p>
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.repository.live
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/6/11 20:04
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * Copyright 2019-2022 com.treasure.mall.biz.repository.live Inc. All rights reserved.
 */
@Repository
public interface LiveRoomRepository extends JpaSearchableRepository<LiveRoomPO, Long> {
    LiveRoomPO findTopByMerchant_MerchantId(Long merchantId);


    /**
     * 修改用户锁定余额
     *
     * @param roomId
     * @param platform
     */
    @Query("update LiveRoomPO room set room.platform=?2 where room.id=?1")
    @Modifying
    @Transactional
    void modifyPlatform(Long roomId, boolean platform);


    /**
     * 根据直播间ID，获取直播间
     *
     * @param ids
     * @return
     */
    List<LiveRoomPO> findByIdInAndAuditStatusAndEnabledIsTrue(List<Long> ids, LiveEnums.AuditStatus auditStatus);


    @Query("update LiveRoomPO room set room.livePlaying=?2 where room.id=?1")
    @Modifying
    @Transactional
    void modifyLivePlaying(Long roomId, int livePlaying);


    /**
     * 设置直播间公告内容
     *
     * @param roomId
     * @param notice
     */
    @Query("update LiveRoomPO room set room.notice=?2,room.enableNotice=true where room.id=?1")
    @Modifying
    @Transactional
    void setNoticeContent(Long roomId, String notice);

    /**
     * 启用或禁用公告内容
     *
     * @param roomId       直播间ID
     * @param enableNotice 是否启用
     */
    @Query("update LiveRoomPO room set room.enableNotice=?2 where room.id=?1")
    @Modifying
    @Transactional
    void enableNotice(Long roomId, boolean enableNotice);
}
